package com;

import org.ns.framework.webmvc.anns.ApiController;
import org.ns.framework.webmvc.anns.LoginVerify;
import org.ns.framework.webmvc.anns.Token;
import org.ns.framework.webmvc.error.resulterror.ApiAlreadyExpiredException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.async.DeferredResult;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

@ApiController
@RequestMapping("test")
public class TestController {
    private BlockingQueue<DeferredResult<String>> blockingQueue = new ArrayBlockingQueue(1024);

    @RequestMapping("xxx")
//    @LoginVerify
    public DeferredResult<String> xxx() {
        DeferredResult<String> stringDeferredResult = new DeferredResult<String>(5000L);
        blockingQueue.add(stringDeferredResult);
        return stringDeferredResult;
    }

    @RequestMapping("xxx2")
//    @LoginVerify
    public String xxx2() throws Exception{
        DeferredResult<String> take = blockingQueue.take();
        take.setResult("aaaaaaaa:" + System.currentTimeMillis());
        return "OK";
    }

    @RequestMapping("value")
    public String value(int a) {
        return "OK";
    }
    @RequestMapping("value2")
    @LoginVerify
    public String value2(@RequestParam("a")  int a, @Token long userId) {
    	
        return "OK: " + userId;
    }

    public static class D {
        private String n = "::" + System.currentTimeMillis();

        public String getN() {
            return n;
        }
    }
}
